﻿import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
//import com.yourcompany.ethernettest 1.0
import QtQuick.Window 2.15

import "." // 导入项目的根目录

Window {
    id: cameraPage
    visible: true
    width: 1200
    height: 768
    title: "camera Test"


    // 这个函数是模拟获取camera状态的函数，实际应用中需要替换为真实的获取状态逻辑
    function getcameraStatus() {
        // 模拟camera状态数据，这里只是随机生成一个字符串作为示例
        var status = "数据更新" + Math.floor(Math.random() * 100);
        return status;
    }

    // 定时器，模拟camera数据更新
    Timer {
        id: cameraTimer
        interval: 1000 // 更新间隔，单位为毫秒
        repeat: true   // 是否重复执行
        onTriggered: {
            // 这里是模拟camera数据更新的地方
            // 假设我们有一个函数getcameraStatus()来获取camera的状态
            var cameraStatus = getcameraStatus();

            // 更新文本显示框的内容
            cameraDataDisplay.text = "camera状态: " + cameraStatus;
        }
    }


    Item {
        id: cameraItem
        anchors.fill : parent

        ColumnLayout {
            id: cameraColumn
            anchors.left : cameraItem.left
            height : cameraItem.height
            width : cameraItem.width * 0.90

            // 上半部分区域
            Rectangle {
                id:cameraTop
                width: cameraColumn.width * 0.99
                height: cameraColumn.height * 0.60
                anchors.top: cameraColumn.top
                anchors.topMargin: 3
                anchors.left: parent.left
                anchors.leftMargin: 3
                border.color: "#c0c0c0"     // 边框颜色
                border.width: 2             // 边框宽度

                color: "#f0f0f0"

                // 上半部分第一个框
                Rectangle {
                    id: cameraSetup
                    width: cameraTop.width * 0.99
                    height: cameraTop.height * 0.49
                    anchors.top: cameraTop.top
                    anchors.topMargin: 6
                    anchors.left: cameraTop.left
                    anchors.leftMargin: 6

                    ColumnLayout {
                        anchors.centerIn: parent
                        spacing: 10

                        RowLayout {
                            id: cameraTestGroup0
                            //anchors.fill: parent
                            width: cameraTop.width * 0.99
                            height: cameraTop.height * 0.10
                            anchors.top: cameraTop.top
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup0Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup0Input
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup0Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup0InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup0frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup0frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton0
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                    cameraTimer.start()
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup1
                            width: cameraTop.width * 1
                            height: cameraTop.height * 0.1
                            anchors.top: cameraTestGroup0.bottom
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup1Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup1Input
                                width: cameraTop.width * 0.25
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup1Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup1InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup1frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup1frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton1
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup2
                            width: cameraTop.width * 1
                            height: cameraTop.height * 0.1
                            anchors.top: cameraTestGroup1.bottom
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup2Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup2Input
                                width: cameraTop.width * 0.25
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup2Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup2InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup2frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup2frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton2
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup3
                            width: cameraTop.width * 1
                            height: cameraTop.height * 0.1
                            anchors.top: cameraTestGroup2.bottom
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup3Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup3Input
                                width: cameraTop.width * 0.25
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup3Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup3InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup3frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup3frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton3
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }
                    }
                }

                // 上半部分第二个框
                Rectangle {
                    id: cameraTopStatus
                    width: cameraTop.width * 0.99
                    height: cameraTop.height * 0.48
                    anchors.top: cameraSetup.bottom
                    anchors.topMargin: 4
                    anchors.left: cameraTop.left
                    anchors.leftMargin: 6

                    ColumnLayout {
                        anchors.centerIn: parent
                        spacing: 10

                        RowLayout {
                            id: cameraTestGroup4
                            //anchors.fill: parent
                            width: cameraTop.width * 0.99
                            height: cameraTop.height * 0.10
                            anchors.top: cameraTopStatus.top
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup4Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup4Input
                                width: cameraTop.width * 0.25
                                height: cameraSetup.height * 0.15
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup4Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup4InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup4frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup4frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton4
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup5
                            //anchors.fill: parent
                            width: cameraTop.width * 0.99
                            height: cameraTop.height * 0.10
                            anchors.top: cameraTopStatus.top
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup5Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup5Input
                                width: cameraTop.width * 0.25
                                height: cameraSetup.height * 0.15
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup5Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup5InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup5frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup5frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton5
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup6
                            //anchors.fill: parent
                            width: cameraTop.width * 0.99
                            height: cameraTop.height * 0.10
                            anchors.top: cameraTopStatus.top
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup6Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup6Input
                                width: cameraTop.width * 0.25
                                height: cameraSetup.height * 0.15
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup6Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup6InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup6frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup6frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton6
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }

                        RowLayout {
                            id: cameraTestGroup7
                            //anchors.fill: parent
                            width: cameraTop.width * 0.99
                            height: cameraTop.height * 0.10
                            anchors.top: cameraTopStatus.top
                            anchors.topMargin: 5
                            anchors.left: cameraTop.left
                            anchors.leftMargin: 5
                            spacing: 15

                            Text {
                                id: cameraTestGroup7Text
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "测试程序选择:"
                            }

                            TextField {
                                id: cameraTestGroup7Input
                                width: cameraTop.width * 0.25
                                height: cameraSetup.height * 0.15
                                placeholderText: "camera test"
                            }

                            Text {
                                id: cameraTestGroup7Interface
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "应用层接口:"
                            }

                            TextField {
                                id: cameraTestGroup7InterfaceInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "/dev/camera-0"
                            }


                            Text {
                                id: cameraTestGroup7frent
                                width: cameraTop.width * 0.2
                                anchors.left: cameraTop.left
                                anchors.leftMargin: 5
                                text: "循环次数:"
                            }

                            TextField {
                                id: cameraTestGroup7frentInput
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                placeholderText: "100"
                            }

                            Button {
                                id: clearDatabutton7
                                text: "测 试"
                                width: cameraTop.width * 0.20
                                height: cameraSetup.height * 0.15
                                onClicked: {
                                    console.log("camera 测试 接口 0")
                                }
                            }
                        }
                    }
                }
            }

            // 错误信息显示
            Text {
                id: cameraLogText
                color: "blue"
                anchors.top: cameraTop.bottom
                anchors.topMargin: 2
                anchors.left: cameraTop.left
                anchors.leftMargin: 10
                text: "输出日志:"
            }

            // 下半部分 显示数据
            Rectangle {
                id: cameraStatusDisplay
                width : cameraColumn.width  * 0.99
                height: cameraColumn.height * 0.35
                anchors.left: cameraTop.left
                anchors.top: cameraLogText.bottom
                anchors.topMargin: 4
                color: "#f0f0f0"
                border.color: "#c0c0c0"     // 边框颜色
                border.width: 2             // 边框宽度

                // 文本显示框
                Text {
                    id: cameraDataDisplay
                    anchors.fill: parent // 使文本框填充整个cameraStatusDisplay
                    text: "这里将显示camera数据" // 初始文本
                    font.pointSize: 14    // 字体大小
                    color: "black"        // 字体颜色
                    wrapMode: Text.WrapAtWordBoundaryOrAnywhere // 自动换行
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignTop
                }
            }

            // 错误信息显示
            Text {
                id: errorDisplay
                color: "red"
                anchors.top: cameraStatusDisplay.bottom
                anchors.topMargin: 2
                anchors.left: cameraTop.left
                anchors.leftMargin: 10
                text: "未连接......"
            }
        }

        Rectangle {
            id: cameraInfo
            anchors.right: cameraItem.right
            height       : cameraItem.height * 0.97
            width        : cameraItem.width * 0.09
            anchors.top: cameraItem.top
            anchors.topMargin: 3
            anchors.rightMargin: 10
            border.color: "#c0c0c0"     // 边框颜色
            border.width: 2             // 边框宽度

            Button {
                id: cameraExitButton
                text: "返 回"
                width: cameraInfo.width * 0.80
                height: cameraInfo.height * 0.05
                anchors.left: cameraInfo.left
                anchors.leftMargin: cameraInfo.width * 0.1
                anchors.top: cameraInfo.top
                anchors.topMargin: 5
                onClicked: {
                    console.log("返回主界面")
                    cameraPage.visible = false
                    mainPage.visible = true
                }
            }

            Button {
                id: cameraClearButton
                text: "清 除"
                width: cameraInfo.width * 0.80
                height: cameraInfo.height * 0.05
                anchors.left: cameraInfo.left
                anchors.leftMargin: cameraInfo.width * 0.1
                anchors.top: cameraInfo.top
                anchors.topMargin: cameraInfo.height * 0.65
                onClicked: {
                    console.log("清除spi文本框信息")
                    cameraDataDisplay.clear()
                }
            }
        }
    }
}
